<?php
if(wp_verify_nonce($_POST['act_update_ticket_booked'],'act_update_ticket_booked'))
{	
	## update customer
	$params = array();
	$params['name'] = $_POST['update_customerName'];
	$params['address'] = $_POST['update_customerAddress'];
	$params['email'] = $_POST['update_customerEmail'];
	$params['tel'] = $_POST['update_customerTel'];
	$params['fax'] = $_POST['update_customerFax'];
	
	$customerID = $_POST['update_customerID'];
	$ticketID   = $_POST['update_ticketID'];
		
	db_update_customer($customerID,$params);
	/*
	$params = array();
			$params['transport']	= $_POST['update_transport_ticket'];
			$params['goway']		= $_POST['update_away'];
			$params['gofrom']		= $_POST['update_from'];
			$params['goto']			= $_POST['update_to'];
			$params['checkIn']		= $_POST['update_INyr'].'-'.$_POST['update_INmo'].'-'.$_POST['update_INdy'].' 00:00:00';
 			$params['timeIn']		= $_POST['update_time_in_ticket'];
			$params['checkOut']		= $_POST['update_OUTyr'].'-'.$_POST['update_OUTmo'].'-'.$_POST['update_OUTdy'].' 00:00:00';
 			$params['timeOut']		= $_POST['update_time_out_ticket'];
			$params['adults']		= $_POST['update_adults'];
			$params['childrent']	= $_POST['update_childrent'];
			$params['infant']		= $_POST['update_infant'];
			$params['onday']		= $_POST['update_book_on_date'];
			$params['status'] 		= $_POST['update_payment'];
	*/		
	db_update_ticket($ticketID);
	
	echo '<span style="color:red;">Update Success!</span>';
}

$ticketID = $_GET['ticket'];
$customerID = $_GET['customer'];
$tickets = db_select_data_by_int("tickets", "ID", $ticketID);
$customers = db_select_data_by_int("customers", "ID", $customerID); 
?>
<div class="view-booking-detail">
<form action="" method="post">
	<h2>Ticket Booked Infomation</h2>
	<table>
		<tr>
			<td class="booked-title">Transport
			<input type="hidden" name="update_customerID" value="<?php echo $customers[0]->ID;?>">
			<input type="hidden" name="update_ticketID" value="<?php echo $ticketID;?>">
			</td>
			<td class="booked-item">
				<select name="update_transport_ticket">
					<option value=""> Select </option>
					<option <?php if($tickets[0]->transport == "car" ) echo 'selected="selected"';?> value="car"> Car </option>
					<option <?php if($tickets[0]->transport == "train" ) echo 'selected="selected"';?> value="train"> Train </option>
					<option <?php if($tickets[0]->transport == "fligh" ) echo 'selected="selected"';?> value="flight"> Flight </option>
				</select>
			</td>
			
			<td class="booked-title">A Way</td>
			<td class="booked-item">
				<select name="update_away">
					<option value=""> Select </option>
					<option <?php if($tickets[0]->goway=="return") echo 'selected="selected"';?> value="return"> Return </option>
					<option <?php if($tickets[0]->goway=="one way") echo 'selected="selected"';?> value="one way"> One way </option>
				</select>				
			</td>
		</tr>
		<tr>
			<?php 
			$where = db_get_where_to_you_go();
			?>
			<td class="booked-title">From</td>
			<td class="booked-item">
				<select name="update_from">
					<option> Select </option>
					<?php 
					foreach ($where as $value) 
					{
						if($tickets[0]->gofrom==$value)
						{
						?>
						<option selected="selected" value="<?php echo $value;?>"> <?php echo $value;?> </option>
						<?php	 	
						}
						else 
						{
						?>
						<option value="<?php echo $value;?>"> <?php echo $value;?> </option>
						<?php 	
						}						
					}
					?>
				</select>
			</td>
			<td class="booked-title">To</td>
			<td class="booked-item">
			<select name="update_to">
					<option> Select </option>
					<?php 
					foreach ($where as $value) 
					{
						if($tickets[0]->goto==$value)
						{
						?>
						<option selected="selected" value="<?php echo $value;?>"> <?php echo $value;?> </option>
						<?php	 	
						}
						else 
						{
						?>
						<option value="<?php echo $value;?>"> <?php echo $value;?> </option>
						<?php 	
						}						
					}
					?>
				</select>
			</td>
		</tr>		
		<tr>
			<td class="booked-title">Check in date</td>
			<td class="booked-item"><span>
											<?php
                                                $originalDate = $tickets[0]->checkIn;
                                                
                                                $newDate_IY = date("Y", strtotime($originalDate));
                                                $newDate_IM = date("m", strtotime($originalDate));
                                                $newDate_ID = date("d", strtotime($originalDate));                                     
                                            ?>
                                            <?php
                                            $date = date('Y');
                                            ?>
                    						<select  name="update_INyr" id="update_INyr">
                    							<?php                    								
                    								for($y = $date; $y <= $date+5 ; $y++)
                    								{
                    									if($y == $newDate_IY)
                    									{
                    									?>
                    										<option selected="selected" value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 										
                    									}
                    									else 
                    									{
                    									?>
                    										<option value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 	
                    									}					
                    								}				
                    							?>
                    						</select>
                                            
                                            
                    						<select  name="update_INmo" id="update_INmo">
                    							<option <?php if($newDate_IM == 1) echo 'selected="selected"';?> value="01">January </option>
                                                <option <?php if($newDate_IM == 2) echo 'selected="selected"';?> value="02">February </option>
                                                <option <?php if($newDate_IM == 3) echo 'selected="selected"';?> value="03">March </option>
                                                <option <?php if($newDate_IM == 4) echo 'selected="selected"';?> value="04">April </option>
                                                <option <?php if($newDate_IM == 5) echo 'selected="selected"';?> value="05">May </option>
                                                <option <?php if($newDate_IM == 6) echo 'selected="selected"';?> value="06">June </option>
                                                <option <?php if($newDate_IM == 7) echo 'selected="selected"';?> value="07">July </option>
                                                <option <?php if($newDate_IM == 8) echo 'selected="selected"';?> value="08">August </option>
                                                <option <?php if($newDate_IM == 9) echo 'selected="selected"';?> value="09">September </option>
                                                <option <?php if($newDate_IM == 10) echo 'selected="selected"';?> value="10">October </option>
                                                <option <?php if($newDate_IM == 11) echo 'selected="selected"';?> value="11">November </option>
                                                <option <?php if($newDate_IM == 12) echo 'selected="selected"';?> value="12">December </option>
                    						</select>
                                            
                                            <select  name="update_INdy" id="update_INdy">
                    							<?php
                    							for($i = 1;$i<=30;$i++)
                    							{
                    								if($i == $newDate_ID)
                    								{
                    								?>
                    									<option selected="selected" value="<?php echo $i;?>"><?php echo $i;?></option>
                    								<?php	
                    								}
                    								else 
                    								{
                    							?>
                    								<option value="<?php echo $i;?>"><?php echo $i;?></option>
                    							<?php
                    								} 								
                    							}	 
                    							?>												 
                    						</select> 
			</span></td>
			
			<td class="booked-title">Check out date</td>
			<td class="booked-item"><span>
											<?php
                                                $originalDate = $tickets[0]->checkOut;
                                                
                                                $newDate_IY = date("Y", strtotime($originalDate));
                                                $newDate_IM = date("m", strtotime($originalDate));
                                                $newDate_ID = date("d", strtotime($originalDate));                                     
                                            ?>
                                            <?php
                                            $date = date('Y');
                                            ?>
                    						<select  name="update_OUTyr" id="update_OUTyr">
                    							<?php                    								
                    								for($y = $date; $y <= $date+5 ; $y++)
                    								{
                    									if($y == $newDate_IY)
                    									{
                    									?>
                    										<option selected="selected" value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 										
                    									}
                    									else 
                    									{
                    									?>
                    										<option value="<?php echo $y;?>"> <?php echo $y;?> </option>
                    									<?php 	
                    									}					
                    								}				
                    							?>
                    						</select>
                                            
                                            
                    						<select  name="update_OUTmo" id="update_OUTmo">
                    							<option <?php if($newDate_IM == 1) echo 'selected="selected"';?> value="01">January </option>
                                                <option <?php if($newDate_IM == 2) echo 'selected="selected"';?> value="02">February </option>
                                                <option <?php if($newDate_IM == 3) echo 'selected="selected"';?> value="03">March </option>
                                                <option <?php if($newDate_IM == 4) echo 'selected="selected"';?> value="04">April </option>
                                                <option <?php if($newDate_IM == 5) echo 'selected="selected"';?> value="05">May </option>
                                                <option <?php if($newDate_IM == 6) echo 'selected="selected"';?> value="06">June </option>
                                                <option <?php if($newDate_IM == 7) echo 'selected="selected"';?> value="07">July </option>
                                                <option <?php if($newDate_IM == 8) echo 'selected="selected"';?> value="08">August </option>
                                                <option <?php if($newDate_IM == 9) echo 'selected="selected"';?> value="09">September </option>
                                                <option <?php if($newDate_IM == 10) echo 'selected="selected"';?> value="10">October </option>
                                                <option <?php if($newDate_IM == 11) echo 'selected="selected"';?> value="11">November </option>
                                                <option <?php if($newDate_IM == 12) echo 'selected="selected"';?> value="12">December </option>
                    						</select>
                                            
                                            <select  name="update_OUTdy" id="update_OUTdy">
                    							<?php
                    							for($i = 1;$i<=30;$i++)
                    							{
                    								if($i == $newDate_ID)
                    								{
                    								?>
                    									<option selected="selected" value="<?php echo $i;?>"><?php echo $i;?></option>
                    								<?php	
                    								}
                    								else 
                    								{
                    							?>
                    								<option value="<?php echo $i;?>"><?php echo $i;?></option>
                    							<?php
                    								} 								
                    							}	 
                    							?>												 
                    						</select> 
			</span></td>
		</tr>	
		<tr>
			<td class="booked-title">Time</td>
			<td class="booked-item">
				<select name="update_time_in_ticket">
                  <?php
                      $current = $tickets[0]->timeIn;
                     // db_get_time_ticket($current); 
                     $html = "";
					for($i=0;$i<=1;$i++)
					{
							if($i==0)
								$a='am';
							else if($i==1)
								$a = 'pm';	
						for($j=0;$j<=12;$j++)
						{			
							$key = $j.' '.$a;	
							if($current==$key)
							{	
								$html.= '<option selected="selected" value="'.$key.'">'.$key.'</option>';
							}
							else 
							{
								$html.= '<option value="'.$key.'">'.$key.'</option>';
							}
						}		
					}	
					echo $html;
                  ?>
                 </select>
			</td>
			
			<td class="booked-title">Time</td>
			<td class="booked-item">
				<select name="update_time_out_ticket">
                  <?php
                      $current = $tickets[0]->timeOut;
                      $html = "";
						for($i=0;$i<=1;$i++)
						{
								if($i==0)
									$a='am';
								else if($i==1)
									$a = 'pm';	
							for($j=0;$j<=12;$j++)
							{			
								$key = $j.' '.$a;	
								if($current==$key)
								{	
									$html.= '<option selected="selected" value="'.$key.'">'.$key.'</option>';
								}
								else 
								{
									$html.= '<option value="'.$key.'">'.$key.'</option>';
								}
							}		
						}	
						echo $html; 
                  ?>
                 </select>
			</td>
		</tr>
		
		<tr>
			<td class="booked-title">Adults  </td>
			<td class="booked-item">
				<input type="text" name="update_adults" value="<?php echo $tickets[0]->adults;?>">
			</td>
			
			<td class="booked-title">Childrent ( 2-11 year ) </td>
			<td class="booked-item">
				<input type="text" name="update_childrent" value="<?php echo $tickets[0]->childrent;?>">
			</td>
		</tr>
	
		<tr>
			<td class="booked-title">Infant ( under 2 year )</td>
			<td class="booked-item">
				<input type="text" name="update_infant" value="<?php echo $tickets[0]->infant;?>">
			</td>
			
			<td class="booked-title">book on date</td>
			<td class="booked-item">
				<select name="update_book_on_date">
					<option value="">Select</option>
					<option <?php if($tickets[0]->onday=="I need to travel on this date") echo 'selected="selected"';?> value="I need to travel on this date">I need to travel on this date</option>
					<option <?php if($tickets[0]->onday=="I just want the cheapest flight") echo 'selected="selected"';?> value="I just want the cheapest flight">I just want the cheapest flight</option>					
				</select>
			</td>
		</tr>
		<tr>
			<td class="booked-title">Order ticket Status</td>
			<td class="booked-item">
				<?php
				$list_payment = db_get_list_payment_status();
				//echo 'dd: '.$tickets[0]->status;	 
				?>
				<select class="select_size" name="update_payment">
				<?php						
				foreach ($list_payment as $key=>$value) 
				{
					if($tickets[0]->status == $key)
					{
					?>
						<option selected="selected" value="<?php echo $key?>"><?php echo $value;?></option>
					<?php 	
					}
					else 
					{
					?>
						<option value="<?php echo $key?>"><?php echo $value;?></option>
					<?php	
					}
				} 
				?>
				</select>
			</td>
			
			<td class="booked-title"></td>
			<td class="booked-item">				
			</td>
		</tr>
		
		
		<tr>
			<td class="booked-title" colspan="4"><h2>Customer Infomation</h2></td>
			
		</tr>
		<tr>
			<td class="booked-title">Customer Name</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerName" value="<?php echo $customers[0]->customerName;?>">
			</span></td>
			
			<td class="booked-title">Customer Address</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerAddress" value="<?php echo $customers[0]->customerAddress;?>">
			</span></td>
		</tr>
		
		<tr>
			<td class="booked-title">Customer Email</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerEmail" value="<?php echo $customers[0]->customerEmail;?>">
			</span></td>
			
			<td class="booked-title">Customer Phone</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerTel" value="<?php echo $customers[0]->customerPhone;?>">
			</span></td>
		</tr>
		<!-- 
		<tr>
			<td class="booked-title">Customer Fax</td>
			<td class="booked-item"><span>
			<input type="text" class="select_size" name="update_customerFax" value="<?php echo $customers[0]->customerFax;?>">
			</span></td>
		</tr>
		 -->
		<tr>
			<td class="booked-title">Customer Comment</td>
			<td class="booked-item"><span><?php echo $customers[0]->customerComment;?></span></td>
		</tr>		
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item">
				<input type="submit" name="update_now_tour" value="Update Now">
				<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=tickets-setting">Return</a>
			</td>
		</tr>
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item"></td>
		</tr>
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item"></td>
		</tr>		
		<tr>
			<td class="booked-title"></td>
			<td class="booked-item"></td>
		</tr>
	</table>		
</div>
<?php wp_nonce_field('act_update_ticket_booked','act_update_ticket_booked');?>
</form>
<?php
db_update_ticket_by_id("tickets","state",1,$tickets[0]->ID,0); 
?>